home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / jcool01.zip / TEST_PRO.C < prev    next >
C/C++ Source or Header  |  1992-08-20  |  2KB  |  69 lines

  1. //
  2. // Copyright (C) 1991 Texas Instruments Incorporated.
  3. //
  4. // Permission is granted to any individual or institution to use, copy, modify,
  5. // and distribute this software, provided that this complete copyright and
  6. // permission notice is maintained, intact, in all copies and supporting
  7. // documentation.
  8. //
  9. // Texas Instruments Incorporated provides this software "as is" without
  10. // express or implied warranty.
  11. //
  12.  
  13. #include <cool/Property.h>
  14. #include <test.h>
  15.  
  16. void test_property () {
  17.   CoolProperty plist;
  18.   CoolString ints = "int";
  19.   CoolString longs = "long";
  20.   CoolString doubles = "double";
  21.   CoolString voidps = "void*";
  22.   CoolValue v0;                    // empty value
  23.   TEST ("get", (plist.get(ints, v0)), FALSE);
  24.   TEST ("get", (plist.get(voidps, v0)), FALSE);
  25.   CoolValue i = (int) 1, ii;            // integer value
  26.   TEST ("put", plist.put(ints, i), TRUE);
  27.   TEST ("get", (plist.get(ints, ii), ((int)ii==1)), TRUE);
  28.   CoolString ints2 = "int";
  29.   TEST ("get", (plist.get(ints2, ii), (ii==i)), TRUE);
  30.   CoolValue l = (long) 10000, ll;        // long value
  31.   TEST ("put", plist.put(longs, l), TRUE);
  32.   TEST ("get", (plist.get(longs, ll), ((long)ll==10000)), TRUE);
  33.   TEST ("find", plist.find(ints), TRUE);
  34.   TEST ("find", plist.find(doubles), FALSE);
  35.   CoolValue d = (double) -15.6, dd;
  36.   TEST ("put", plist.put(doubles, d), TRUE);
  37.   TEST ("get", (plist.get(doubles, dd), ((double)dd==-15.6)), TRUE);
  38.   TEST ("remove(ints)", plist.remove(ints), TRUE);
  39.   TEST ("remove(ints)", plist.remove(ints), FALSE);
  40.   TEST ("get", (plist.get(ints, ii)), FALSE);
  41.   TEST ("puts", (plist.put(ints, (i=(int)1)), plist.put(ints2, (i=(int)2)),
  42.          plist.get(ints, ii), ((int)ii==2)), TRUE);
  43.   void* v1 = &v0;                // void* value
  44.   void* v2 = &i;
  45.   CoolValue v = (void*) NULL, vv;
  46.   CoolString void2ps = "void2*";
  47.   TEST ("put", (plist.put(voidps, (v=v1)), plist.get(voidps, vv) && 
  48.         ((void*)vv==v1)), TRUE);
  49.   TEST ("put", (plist.put(void2ps, (v=v2)), plist.get(void2ps, vv) && 
  50.         ((void*)vv==v2)), TRUE);
  51.   cout << plist << "=" << &plist << endl;
  52.   TEST ("<<", TRUE, TRUE);
  53. }
  54.  
  55. void test_leak () {
  56.   for (;;)
  57.     test_property();
  58. }
  59.  
  60. int main (void) {
  61.   START("CoolProperty");
  62.   test_property();
  63. #if LEAK
  64.   test_leak();
  65. #endif
  66.   SUMMARY();
  67.   return 0;
  68. }
  69.